﻿using System.Security.Cryptography.X509Certificates;

namespace Random2
{/// <summary>
/// 随机生成字母小游戏
/// </summary>
    internal class Program
    {  //设置实验次数
        const int length = 10;

        static void Main(string[] args)
        {
            //耗时
            double span = 0;
            //错误次数
            int error = 0;
            int i;

            for (i = 1; i <= length; i++)
            {   //随机生成26个字母
                Random rnd = new Random();
                int a = rnd.Next(0, 52);
                int ASCII;
                if (a < 26) ASCII = a + 65;
                else ASCII = a + (97 - 26);
                char letter = (char)ASCII;
                //开始时间               
                DateTime before = DateTime.Now;
                Console.Clear();

                //显示耗时，测试次数和错误次数
                Console.WriteLine($"现在是第{i}次随机测试");

                Console.WriteLine(letter.ToString());

                bool flag = false;
                do
                {//接受用户输入
                    char input = Console.ReadKey().KeyChar;
                    //开始进行比对是否正确
                    if (input == letter)
                        break;
                    else error += 1;
                } while (flag == false);
                //一次完成后的时间
                DateTime after = DateTime.Now;
                //耗时
                span += (after - before).TotalSeconds;
                Console.WriteLine($"现在耗时已为{span},错误次数为{error/2}");
                Console.ReadKey();
            }


        }
    }
}
